class P10656_39643 {

  public static void main(String[] args) {
      String line = readLn();
      while (!line.equals("0")) {
              process(Integer.parseInt(line));
              line = readLn();
              System.out.println();
//              if (!line.equals("0"))System.out.println();
      }
  }


      private static void process(int i) {
    	  StringBuffer sb = new StringBuffer();
              int counter = 0;
              for (int k = 0; k < (i-1); k++) {
                      String number = readLn();

                      if (!number.equals("0")) {
                              sb.append(number + " ");
                              counter++;
                      }
              }
              String number = readLn();
              if (!number.equals("0")) {
            	  	  sb.append(number);
                      counter++;
              }

              if (counter == 0) {
            	  	  sb.append("0");
              }
              
              System.out.print(sb.toString().trim());
      }


      static String readLn() {
      String newLine = System.getProperty("line.separator");
      StringBuffer buffer = new StringBuffer();
      int car = -1;
      try {
          car = System.in.read();
          while ((car > 0) && (car != newLine.charAt(0))) {
              buffer.append((char)car);
              car = System.in.read();
          }
          if (car == newLine.charAt(0))
          System.in.skip(newLine.length() - 1);
      } catch (java.io.IOException e) { return (null);}
      if ((car < 0) && (buffer.length() == 0)) return (null);
      return (buffer.toString()).trim();
  }

}